package com.zrx.controller;

import com.zrx.domain.ResponseResult;
import com.zrx.domain.entity.User;
import com.zrx.enums.AppHttpCodeEnum;
import com.zrx.exception.SystemException;
import com.zrx.service.BlogLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 张荣欣
 * @create ：2022/9/16  16:33
 */
@RestController
@RequestMapping("/")
@Api(tags = "登录")
public class BlogLoginController {

    @Autowired
    private BlogLoginService blogLoginService;

    @PostMapping("/login")
    @ApiOperation(value = "登录验证",notes = "登录验证")
    public ResponseResult login(@RequestBody User  user){
        if(!StringUtils.hasText(user.getUserName())){
            //提示 必须传用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);

        }
        return blogLoginService.login(user);
    }

    @PostMapping("/logout")
    @ApiOperation(value = "退出登录",notes = "退出登录")
    public ResponseResult logout(){
        return blogLoginService.logout();
    }


}
